home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fsutil / fsutilSubr.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  7KB  |  313 lines

  1. /* 
  2.  * fsutilSubr.c --
  3.  *
  4.  *    Miscellaneous routines.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifndef lint
  11. static char rcsid[] = "$Header: /sprite/src/kernel/fsutil/RCS/fsutilSubr.c,v 9.2 90/10/08 13:19:20 mendel Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14.  
  15. #include <sprite.h>
  16.  
  17. #include <fs.h>
  18. #include <vm.h>
  19. #include <rpc.h>
  20. #include <fsutil.h>
  21. #include <fsdm.h>
  22. #include <fslcl.h>
  23. #include <fsprefix.h>
  24. #include <fsNameOps.h>
  25. #include <fsutilTrace.h>
  26. #include <fspdev.h>
  27. #include <fsStat.h>
  28. #include <devDiskLabel.h>
  29. #include <dev.h>
  30. #include <sync.h>
  31. #include <timer.h>
  32. #include <proc.h>
  33. #include <trace.h>
  34. #include <hash.h>
  35. #include <fsrmt.h>
  36.  
  37. #include <stdio.h>
  38.  
  39.  
  40.  
  41. /*
  42.  *----------------------------------------------------------------------
  43.  *
  44.  * Fsutil_DomainInfo --
  45.  *
  46.  *    Return info about the given domain.
  47.  *    FIX ME FIX ME FIX ME
  48.  *    This should be replaced by a call through the domain switch.
  49.  *    The prefix table module has the domain type, so can do this.
  50.  *    For now, we infer the domain type from the stream type.
  51.  *
  52.  * Results:
  53.  *    A return status.
  54.  *
  55.  * Side effects:
  56.  *    None.
  57.  *
  58.  *----------------------------------------------------------------------
  59.  */
  60. ReturnStatus 
  61. Fsutil_DomainInfo(fileIDPtr, domainInfoPtr)
  62.     Fs_FileID        *fileIDPtr;    /* FileID from the prefix table,
  63.                      * This can be changed to make
  64.                      * it match with what a user sees
  65.                      * when it stats the file.  This
  66.                      * is important when computing
  67.                      * the current directory in getwd(). */
  68.     Fs_DomainInfo    *domainInfoPtr;    /* Fill in with # free blocks, etc */
  69. {
  70.     ReturnStatus    status;
  71.  
  72.     switch (fileIDPtr->type) {
  73.     case FSIO_LCL_FILE_STREAM:
  74.         status = Fsdm_DomainInfo(fileIDPtr, domainInfoPtr);
  75.         break;
  76.     case FSIO_PFS_NAMING_STREAM:
  77.     case FSIO_RMT_FILE_STREAM:
  78.         status = Fsrmt_DomainInfo(fileIDPtr, domainInfoPtr);
  79.         break;
  80.     case FSIO_LCL_PSEUDO_STREAM:
  81.         status = FspdevPfsDomainInfo(fileIDPtr, domainInfoPtr);
  82.         break;
  83.     default:
  84.         printf("Fsutil_DomainInfo: Unexpected stream type <%d>\n",
  85.             fileIDPtr->type);
  86.         status = FS_DOMAIN_UNAVAILABLE;
  87.         break;
  88.     }
  89.     if (status != SUCCESS) {
  90.     domainInfoPtr->maxKbytes = -1;
  91.     domainInfoPtr->freeKbytes = -1;
  92.     domainInfoPtr->maxFileDesc = -1;
  93.     domainInfoPtr->freeFileDesc = -1;
  94.     domainInfoPtr->blockSize = -1;
  95.     }
  96.  
  97.     return(status);
  98. }
  99.  
  100. /*
  101.  *----------------------------------------------------------------------
  102.  *
  103.  * Fsutil_FileError --
  104.  *
  105.  *    Print an error message about a file.
  106.  *
  107.  * Results:
  108.  *    None.
  109.  *
  110.  * Side effects:
  111.  *    None.
  112.  *
  113.  *----------------------------------------------------------------------
  114.  */
  115. void
  116. Fsutil_FileError(hdrPtr, string, status)
  117.     Fs_HandleHeader *hdrPtr;
  118.     char *string;
  119.     int status;
  120. {
  121.     if (hdrPtr == (Fs_HandleHeader *)NIL) {
  122.     printf("(NIL handle) %s: ", string);
  123.     } else {
  124.     Net_HostPrint(hdrPtr->fileID.serverID,
  125.               Fsutil_FileTypeToString(hdrPtr->fileID.type));
  126.     printf(" \"%s\" <%d,%d> %s: ", Fsutil_HandleName(hdrPtr),
  127.         hdrPtr->fileID.major, hdrPtr->fileID.minor, string);
  128.     }
  129.     Fsutil_PrintStatus(status);
  130.     printf("\n");
  131. }
  132.  
  133. /*
  134.  *----------------------------------------------------------------------
  135.  *
  136.  * Fsutil_PrintStatus --
  137.  *
  138.  *    Print out an error status, using a mnemonic if possible.
  139.  *
  140.  * Results:
  141.  *    None.
  142.  *
  143.  * Side effects:
  144.  *    A print statement.
  145.  *
  146.  *----------------------------------------------------------------------
  147.  */
  148. void
  149. Fsutil_PrintStatus(status)
  150.     int status;
  151. {
  152.     switch (status) {
  153.     case SUCCESS:
  154.         break;
  155.     case FS_DOMAIN_UNAVAILABLE:
  156.         printf("domain unavailable");
  157.         break;
  158.     case FS_VERSION_MISMATCH:
  159.         printf("version mismatch");
  160.         break;
  161.     case FAILURE:
  162.         printf("cacheable/busy conflict");
  163.         break;
  164.     case RPC_TIMEOUT:
  165.         printf("rpc timeout");
  166.         break;
  167.     case RPC_SERVICE_DISABLED:
  168.         printf("server rebooting");
  169.         break;
  170.     case FS_STALE_HANDLE:
  171.         printf("stale handle");
  172.         break;
  173.     case DEV_RETRY_ERROR:
  174.     case DEV_HARD_ERROR:
  175.         printf("DISK ERROR");
  176.         break;
  177.     case FS_NO_DISK_SPACE:
  178.         printf("out of disk space");
  179.     default:
  180.         printf("<%x>", status);
  181.         break;
  182.     }
  183. }
  184.  
  185. /*
  186.  *----------------------------------------------------------------------
  187.  *
  188.  * Fsutil_FileTypeToString --
  189.  *
  190.  *    Map a stream type to a string.  Used for error messages.
  191.  *
  192.  * Results:
  193.  *    A string.
  194.  *
  195.  * Side effects:
  196.  *    None.
  197.  *
  198.  *----------------------------------------------------------------------
  199.  */
  200. char *
  201. Fsutil_FileTypeToString(type)
  202.     int type;
  203. {
  204.     register char *fileType;
  205.  
  206.     switch (type) {
  207.     case FSIO_STREAM:
  208.         fileType = "Stream";
  209.         break;
  210.     case FSIO_LCL_FILE_STREAM:
  211.         fileType = "File";
  212.         break;
  213.     case FSIO_RMT_FILE_STREAM:
  214.         fileType = "RmtFile";
  215.         break;
  216.     case FSIO_LCL_DEVICE_STREAM:
  217.         fileType = "Device";
  218.         break;
  219.     case FSIO_RMT_DEVICE_STREAM:
  220.         fileType = "RmtDevice";
  221.         break;
  222.     case FSIO_LCL_PIPE_STREAM:
  223.         fileType = "Pipe";
  224.         break;
  225.     case FSIO_RMT_PIPE_STREAM:
  226.         fileType = "RmtPipe";
  227.         break;
  228. #ifdef notdef
  229.     case FS_LCL_NAMED_PIPE_STREAM:
  230.         fileType = "NamedPipe";
  231.         break;
  232.     case FS_RMT_NAMED_PIPE_STREAM:
  233.         fileType = "RmtNamedPipe";
  234.         break;
  235. #endif
  236.     case FSIO_CONTROL_STREAM:
  237.         fileType = "PdevControlStream";
  238.         break;
  239.     case FSIO_SERVER_STREAM:
  240.         fileType = "SrvStream";
  241.         break;
  242.     case FSIO_LCL_PSEUDO_STREAM:
  243.         fileType = "LclPdev";
  244.         break;
  245.     case FSIO_RMT_PSEUDO_STREAM:
  246.         fileType = "RmtPdev";
  247.         break;
  248.     case FSIO_PFS_CONTROL_STREAM:
  249.         fileType = "PfsControlStream";
  250.         break;
  251.     case FSIO_PFS_NAMING_STREAM:
  252.         fileType = "PfsNamingStream";
  253.         break;
  254.     case FSIO_LCL_PFS_STREAM:
  255.         fileType = "LclPfs";
  256.         break;
  257.     case FSIO_RMT_PFS_STREAM:
  258.         fileType = "RmtPfs";
  259.         break;
  260. #ifdef INET
  261.     case FSIO_RAW_IP_STREAM:
  262.         fileType = "RawIp Socket";
  263.         break;
  264.     case FSIO_UDP_STREAM:
  265.         fileType = "UDP Socket";
  266.         break;
  267.     case FSIO_TCP_STREAM:
  268.         fileType = "TCP Socket";
  269.         break;
  270. #endif
  271. #ifdef notdef
  272.     case FS_RMT_UNIX_STREAM:
  273.         fileType = "UnixFile";
  274.         break;
  275.     case FS_RMT_NFS_STREAM:
  276.         fileType = "NFSFile";
  277.         break;
  278. #endif
  279.     default:
  280.         fileType = "<unknown file type>";
  281.         break;
  282.     }
  283.     return(fileType);
  284. }
  285.  
  286. /*
  287.  *----------------------------------------------------------------------
  288.  *
  289.  * Fsutil_GetFileName --
  290.  *
  291.  *    Return a pointer to the file name for the given stream.
  292.  *
  293.  * Results:
  294.  *    Pointer to file name from handle of given stream.
  295.  *
  296.  * Side effects:
  297.  *    None.
  298.  *
  299.  *----------------------------------------------------------------------
  300.  */
  301. char *
  302. Fsutil_GetFileName(streamPtr)
  303.     Fs_Stream    *streamPtr;
  304. {
  305.     if (streamPtr->hdr.name != (char *)NIL) {
  306.     return(streamPtr->hdr.name);
  307.     } else if (streamPtr->ioHandlePtr != (Fs_HandleHeader *)NIL) {
  308.     return(streamPtr->ioHandlePtr->name);
  309.     } else {
  310.     return("(noname)");
  311.     }
  312. }
  313.